From efe6d12251770146719a478f95054a79c634f3e5 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 25 Apr 2007 09:44:20 +0100 Subject: [PATCH] xend: Fix race in vfb/vkbd device setup. 1. XendDomainInfo._createDevices() gets a list of devices to be created from XendConfig.ordered_device_refs(). On a simple guest, this has 4 devices, vfb, vbd, vif, vkbd - in that order. 2. It iterates over those devices, creating the appropriate DevController subclass instance, and then calling createDevice() on that object. 3. When createDevice() is called on the vfb device, it spawns xen-vncfb daemon. 4. During startup xen-vncfb writes into the backend paths /local/domain/0/backend/vfb/0 And /local/domain/0/backend/vkbd/0 5. When createDevice() is called on the vkbd device in XenD, if the 2nd xenstore path write from step 4 has occurred, then you'll hit the 'Device 0 (vkbd) is already connected' error. If the 2nd path write didn't complete yet then everything is fine. I think the reason it often works once after boot is that loading xen-vncfb from disk the first time around is just enough of a slow down to ensure step 5 occurs before the 2nd xenstore write in step 4 has occurred. The key seems to be to ensure the vkbd device is initialized in xenstore before the vfb device - this ensures all the xenstored setup from XenD is complete before the xen-vncfb daemon starts. I'm now able to create & destroy a domain many times over with this patch & never hit the error message any more. Signed-off-by: Daniel P. Berrange --- tools/python/xen/xend/XendConfig.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/python/xen/xend/XendConfig.py b/tools/python/xen/xend/XendConfig.py index 86b643e2d8..7622c8b809 100644 --- a/tools/python/xen/xend/XendConfig.py +++ b/tools/python/xen/xend/XendConfig.py @@ -1278,10 +1278,21 @@ class XendConfig(dict): return sxpr def ordered_device_refs(self): - result = (self['console_refs'] + - self['vbd_refs'] + - self['vif_refs'] + - self['vtpm_refs']) + result = [] + # vkbd devices *must* be before vfb devices, otherwise + # there is a race condition when setting up devices + # where the daemon spawned for the vfb may write stuff + # into xenstore vkbd backend, before DevController has + # setup permissions on the vkbd backend path. This race + # results in domain creation failing with 'device already + # connected' messages + result.extend([u for u in self['devices'].keys() if self['devices'][u][0] == 'vkbd']) + + result.extend(self['console_refs'] + + self['vbd_refs'] + + self['vif_refs'] + + self['vtpm_refs']) + result.extend([u for u in self['devices'].keys() if u not in result]) return result -- 2.30.2